/*
 * Event.h
 *
 *  Created on: 2014年5月28日
 *      Author: ellzu
 */

#ifndef EVENT_H_
#define EVENT_H_

#include <map>
#include <pthread.h>
#include <string>

namespace EventRunLoop {

class EventQueue;
class EventContext;

class Event {
public:
	Event(int type_=0,int subType_=0,bool isAsync=true);
	virtual ~Event();

public :
	int type;
	int subType; // set by user to confirm sub type
	void *userContent; //content set by user , and delete by user

	/**
	 * add context to event by user , the contex obj will delete on ~event.
	 */
	void addContext(const std::string &key,EventContext *cx);
	EventContext* contextWithKey(const std::string &key);

	/**
	 * add unknow type context by user ,and un auto delete
	 */
	void addVcontext(const std::string &key,void *cx);
	void* vContextWithKey(const std::string &key);

private:
	std::map<std::string,EventContext* > _mapContext;

	friend class EventQueue;

	pthread_mutex_t _mutex;
	pthread_cond_t _cond;
	bool _isAsync;

};

} /* namespace EventRunLoop */

#endif /* EVENT_H_ */
